package com.imay.live.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.imay.live.helper.SystemNoticeHelper;
import com.imay.live.model.SystemNoticeModel;
import com.imay.live.utils.TimeUtil;
import com.imay.live.R;


import java.util.List;

/**
 * Created by  nick on 2017/4/20 0020.
 */

public class SystemNoticeAdapter extends BaseQuickAdapter<SystemNoticeModel,BaseViewHolder> {

    public SystemNoticeAdapter( List<SystemNoticeModel> data) {

        super(R.layout.item_system_notice, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, SystemNoticeModel item) {
        helper.setText(R.id.tv_time_system_notice, TimeUtil.getFormatTime(item.getCreateTime()));
        int stringId = SystemNoticeHelper.getTextByType(item.getContentType());
        int imageId = SystemNoticeHelper.getIconByType(item.getContentType());
        if (stringId!=0){
            helper.setText(R.id.tv_name_system_notice,stringId);
        }else{
            helper.setText(R.id.tv_name_system_notice,"");
        }
        if (imageId!=0){
            helper.setBackgroundRes(R.id.iv_head_img_system_notice,imageId);
        }else{
            helper.setBackgroundRes(R.id.iv_head_img_system_notice,R.mipmap.placeholder);
        }
        if (item.getContentId()==0) {
            helper.setText(R.id.tv_content_system_notice, item.getContent());
        }else{
            helper.setText(R.id.tv_content_system_notice, SystemNoticeHelper.getContent(mContext,item.getContentType(), (int) item.getContentId(),item.getContentParameters()));
        }
        helper.setVisible(R.id.tv_system_notice_unread,!item.hasReaded());
        helper.setText(R.id.tv_system_notice_unread,item.getUnReadNum()+"");
        helper.addOnClickListener(R.id.tv_system_notice_delete);

    }
}
